package modelo.armas;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import vista.VistaFactory;
import vista.VistaMovil;
import com.thoughtworks.xstream.XStream;
import modelo.desplazadores.DesplazadorLineaRecta;
import modelo.naves.NaveAlgo42;
import modelo.util.Vector;
import static modelo.SetUps.VELOCIDAD_PICKUP;

public class PickUpArmaBombardero extends PickUp{

	public PickUpArmaBombardero(Vector pos, Vector dir){
		desplazador = new DesplazadorLineaRecta(pos, dir, VELOCIDAD_PICKUP);
	}
	
	public void chocarConAlgo42(NaveAlgo42 algo42) {
		// no se agrega el laser porque por defecto 
		// el algo42 ya lo tiene.
		ArmaCompuesta arma = new ArmaCompuesta();
		Armas armaAux = new Cohete (new BandoAlgo42()); 
		arma.addArma(armaAux);
		armaAux = new TorpedoRastreador(new BuscaEnemigos());
		arma.addArma(armaAux);
		algo42.tomarArma(arma);
		this.seguirActuando = false;		
	}
	
	public void persistir(String file) throws IOException{
		XStream xstream = new XStream();
		xstream.alias("PickUpArmaBombardero", PickUpArmaBombardero.class);
		FileWriter xmlFile = new FileWriter(file);
		xstream.toXML(this,xmlFile);
	}
	
	public PickUpArmaBombardero(String file) throws IOException{
		XStream xstream = new XStream();
		PickUpArmaBombardero objAux;
		xstream.alias("PickUpArmaBombardero", PickUpArmaBombardero.class);
		objAux = (PickUpArmaBombardero)xstream.fromXML(new FileReader(file));
		desplazador = objAux.desplazador;
				
	}
	
	public VistaMovil getVista (VistaFactory vistaFactory){
		return vistaFactory.getVistaPickUpArma(this);
	}
	

}
